//2009/08/23 01:13:38
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class Thimbles
{
public:
    int thimbleWithBall(vector <string> swaps)
    {
		int ret = 1;
		for(int i=0; i<swaps.size(); i++)
		{
			stringstream ss(swaps[i]);
			int a, b;
			char c;
			ss >> a >> c >> b;
			if(a == ret) ret = b;
			else if(b == ret) ret = a;
		}
		return ret;
    }
};
